package com.example.eureka_client.service.impl;

import com.example.eureka_client.entity.AttentionUser;
import com.example.eureka_client.mapper.AttentionUserMapper;
import com.example.eureka_client.service.IAttentionUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户关注其他用户关联表 服务实现类
 * </p>
 *
 * @author plj
 * @since 2022-04-17
 */
@Service
public class AttentionUserServiceImpl extends ServiceImpl<AttentionUserMapper, AttentionUser> implements IAttentionUserService {
    @Override
    public List<String> getAllByUserId(String userId){
        List<AttentionUser> attentionUsers = baseMapper.getAllByUserId(userId);
        List<String> userIds = new ArrayList<>();

        for(AttentionUser attentionUser: attentionUsers) userIds.add(attentionUser.getToId());

        return userIds;
    }

    @Override
    public List<String> getAllByToId(String toId){
        List<AttentionUser> attentionUsers = baseMapper.getAllByToId(toId);
        List<String> toIds = new ArrayList<>();

        for(AttentionUser attentionUser: attentionUsers) toIds.add(attentionUser.getUserId());

        return toIds;
    }

    @Override
    public boolean delAttention(String userId, String toId){
        return baseMapper.delAttention(userId, toId);
    }
}
